/*
 * ClientSendingThread.cpp
 *
 *  Created on: Nov 5, 2012
 *      Author: lucas
 */

#include "ClientSendingThread.h"
#include "../common/SocketErrorException.h"
#include "../common/CommunicationSocket.h"
#include "Client.h"

ClientSendingThread::ClientSendingThread(CommunicationSocket& csck, Client& c) : sck(csck), client(c) {
}

ClientSendingThread::~ClientSendingThread() {
}

void ClientSendingThread::ejecutar() {
	std::string msg;
	while (this->running()) {
		msg = sendingQueue.pop();
		try {
			sck.enviar(msg);
		}
		catch (SocketErrorException& exc) {
			client.disconnect();
		}
	}
}

void ClientSendingThread::send(std::string& msg) {
	sendingQueue.push(msg);
}

